<?php
error_reporting(0);
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods:POST,GET");
header("Access-Control-Allow-Headers:x-requested-with,content-type");
header("Content-type:text/json;charset=utf-8");
$wd=empty($_GET['wd'])?'':$_GET['wd'];
$data=json_decode(file_get_contents('http://www.zuidazy3.net/inc/feifei3.4/?wd='.$wd),true);
$jxUrl='http://www.apiokzy.com/inc/feifei3/?url=';
if(!empty($wd)){
    for($i=0;$i<count($data['data']);$i++){
        $json_data[$i]['id']=$data['data'][$i]['vod_id'];
        $json_data[$i]['name']=$data['data'][$i]['vod_name'];
        $json_data[$i]['actor']=$data['data'][$i]['vod_actor'];
        $json_data[$i]['director']=$data['data'][$i]['vod_director'];
        $json_data[$i]['content']=$data['data'][$i]['vod_content'];
        $json_data[$i]['img']=$data['data'][$i]['vod_pic'];
        $json_data[$i]['area']=$data['data'][$i]['vod_area'];
        $json_data[$i]['language']=$data['data'][$i]['vod_language'];
        $json_data[$i]['year']=$data['data'][$i]['vod_year'];
        $json_data[$i]['url']=urlPro($data['data'][$i]['vod_url']);
    }
    $jsonData['status']='200';
    $jsonData['data']=$json_data;
    echo json_encode($jsonData);
}

function urlPro($info){
    $zl=[];
    $m3u8=[];
    $suArr = explode("$$$",$info);
    foreach ($suArr as $b){
        $v = explode("\n",$b);
        $d[] =$v;
    }
    foreach($d as $v){
        foreach ($v as $key=>$cc){
            $u = explode("$",$cc);
            if(strpos($u[1] ,'.m3u8')){
                $temp['url']= $u[1];
                $temp['title'] = $u[0];
                $temp['vtype']='m3u8';
                array_push($m3u8,$temp);
            }else{
                $temp['url'] = $u[1];
                $temp['title'] = $u[0];
                $temp['vtype']='zl';
                array_push($zl,$temp);
            }
        }
    }
    $video['zl']=$zl;
    $video['m3u8']=$m3u8;
    return $video;
}
function curl($url,$timeout = 10) {  
	$user_agent = "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/62.0.3202.94 Safari/537.36";  
	$curl = curl_init();                                        //初始化 curl
	curl_setopt($curl, CURLOPT_URL, $url);                      //要访问网页 URL 地址
	curl_setopt($curl, CURLOPT_USERAGENT,$user_agent);		   //模拟用户浏览器信息 
	curl_setopt($curl, CURLOPT_REFERER,$url) ;               //伪装网页来源 URL
	curl_setopt($curl, CURLOPT_AUTOREFERER, 1);                //当Location:重定向时，自动设置header中的Referer:信息                   
	curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);             //数据传输的最大允许时间 
	curl_setopt($curl, CURLOPT_HEADER, 0);                     //不返回 header 部分
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);            //返回字符串，而非直接输出到屏幕上
	curl_setopt($curl, CURLOPT_FOLLOWLOCATION,1);             //跟踪爬取重定向页面
	curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, '0');        //不检查 SSL 证书来源
	curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, '0');        //不检查 证书中 SSL 加密算法是否存在
	curl_setopt($curl, CURLOPT_ENCODING, '');	          //解决网页乱码问题
	$content = curl_exec($curl);
	curl_close($curl);
	return $content;
}